package oms.dao;

import java.util.Collection;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import oms.entities.Item;
import oms.entities.Order;
import oms.entities.User;


@Repository
public class ItemDAOImpl implements ItemDAO {

	
		@Autowired
		private SessionFactory sessionFactory;
	
		// OK
		public void createItem(Item item) {
		
			sessionFactory.getCurrentSession().save(item);
		}

		// OK
		public void updateItem(Long itemId) {
			
			Item item = (Item) sessionFactory.getCurrentSession().load(Item.class, itemId);
			
			if(null != item) sessionFactory.getCurrentSession().update(item);
		}

		// OK
		public Item getItemByName(String name) {
			
			Item item = (Item) sessionFactory.getCurrentSession().load(Order.class, name);
		
			return item;
		}

		// OK
		public Item getItemByDescription(String description) {
			
			Item item = (Item) sessionFactory.getCurrentSession().load(Order.class, description);
		
			return item;
		}

		// OK
		public void deleteItem(Long itemId) {
			
				Item item = (Item) sessionFactory.getCurrentSession().load(Order.class, itemId);
			
				if (null != item) sessionFactory.getCurrentSession().delete(item);
		}

		// OK
		@SuppressWarnings("unchecked")
		public List<Item> itemsList() {
			
				return sessionFactory.getCurrentSession().createQuery("from Item").list();
		}

	
		@SuppressWarnings("rawtypes")
		public Collection getItemsByUserOrder(User user) {
		
				return null;
		}
}